//
//  MenuTableViewCell.m
//  PopMenuTableView
//
//  Created by 孔繁武 on 16/8/2.
//  Copyright © 2016年 KongPro. All rights reserved.
//

#import "MenuTableViewCell.h"

@implementation MenuTableViewCell {

}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUpUI];
    }
    return self;
}

- (void)setUpUI{

    @autoreleasepool {
        self.backgroundColor = nil;
        self.backgroundColor = [UIColor clearColor];
        
        if (self.textLabel != nil) {
            self.textLabel.font = [UIFont systemFontOfSize:14];
            self.textLabel.textColor = [UIColor colorWithRed:26.f/255.f green:26.f/255.f blue:26.f/255.f alpha:1.f];
            if(self.titleColor != nil){
                self.textLabel.textColor = _titleColor;
            }
        }

        //列点击样式
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }

}

- (void)setTitleColor:(UIColor *)titleColor {
    _titleColor = titleColor;
    
    if(self.titleColor != nil){
        self.textLabel.textColor = _titleColor;
    }
}

- (void)setMenuModel:(MenuModel *)menuModel{
    _menuModel = menuModel;
    self.imageView.image = [UIImage imageNamed:menuModel.imageName];
    self.textLabel.text = menuModel.itemName;

    //右边视图
    if(![menuModel.rightName isEqualToString:@""]){

        __block typeof(UILabel) *labRight = nil;

        //存在，更新
        if ([self.accessoryView isKindOfClass:[UILabel classForCoder]]) {
            labRight = (UILabel *)self.accessoryView;
        }
        //新建
        else {
            CGRect rect = CGRectMake(self.frame.size.width - 135 - 15, (self.frame.size.height - 21) * 0.5, 135, 21);
            labRight = [[UILabel alloc] initWithFrame:rect];
            labRight.textColor = [UIColor systemGrayColor]; //[UIColor colorWithRed:253.f/255.f green:126.f/255.f blue:24.f/255.f alpha:1];
            labRight.textAlignment = NSTextAlignmentRight;
            labRight.font = [UIFont systemFontOfSize:14];

            self.accessoryView = labRight;
        }

        labRight.text = menuModel.rightName;
    }
    else{
        self.accessoryView = nil;
    }
}

@end
